package cn.gov.pbc.gd.credit.web.controller.report;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.alibaba.fastjson.JSON;
import com.liu.jbase.ResultVo;
import com.liu.jbase.constant.ResCode;
import com.liu.jbase.controller.impl.BaseControllerImpl;

import cn.gov.pbc.gd.credit.core.service.report.IReportService;
import cn.gov.pbc.gd.credit.vo.report.ChargeVo;
import cn.gov.pbc.gd.credit.vo.report.ResChargeReportVo;

@Controller
@RequestMapping("/report")
public class ReportController extends BaseControllerImpl<ResChargeReportVo, ChargeVo, IReportService> {

    @Autowired
    IReportService reportService;


    @RequestMapping("/chargeReport")
    public String chargeReport(ChargeVo chargeVo, Model model) {
        model.addAttribute("result", reportService.chargeReport(chargeVo));
        model.addAttribute("countReport", JSON.toJSON(reportService.countReport(chargeVo).getData()));
        model.addAttribute("feeReport", JSON.toJSON(reportService.feeReport(chargeVo).getData()));
        model.addAttribute("charge", JSON.toJSON(chargeVo));
        return "report/chargeReport";
    }
    
    @RequestMapping("/charge/total")
    public String chargeTotal(ChargeVo chargeVo, Model model, HttpServletRequest request) {
    	
    	String cid = chargeVo.getCorp();
    	model.addAttribute("result", reportService.chargeTotal(chargeVo, request));
    	chargeVo.setCorp(cid);
        model.addAttribute("charge", JSON.toJSON(chargeVo));
        return "report/chargeReport";
    }
    
    @RequestMapping(value="/charge/excel", method = RequestMethod.GET)
	public void downloadFile(ChargeVo vo, HttpServletRequest request, HttpServletResponse response) throws IOException {
		
		ResultVo<String> resultVo = reportService.chargeExport(vo, request, response);
		
		if( ! ResCode.SUCCESS.equals(resultVo.getCode())){
			return ;
		}

	}
}
